import random
win_times=0
while win_times <=2:
    player=int(input("请输入：剪刀(0) 石头(1) 布(2):"))

    computer = random.randint(0,2)

    if((player==0) and (computer==2)) or ((player==1) and (computer==0)) or ((player==3) and (computer == 1)):
        win_times +=1
        print(f'您已经获胜{win_times}局 继续加油')
        continue
    elif player==computer:
        print('平局 再来一局')
        continue
    else:
        print('您输了 洗洗手 决战到天亮')





import random 
class Player:
    def __init__(self):
        self.dict = {0 :'剪刀', 1 : '石头', 2 : '布'}

    def gesture(self):
        player_input = int(input('请输入(0剪刀 1石头 2布):'))
        return self.dict[player_input]
    
class AIPlayer(Player):
    play_data = []
    def ai_gesture(self):
        while True:
            computer = random.randint(0, 2)
            if len(self.play_data) >= 4:
                max_prob = max(self.play_data, key=self.play_data.count)
                if max_prob == '剪刀':
                    return '石头'
                elif max_prob == '石头':
                    return '布'
                else:
                    return '剪刀'
            else:
                return self.dict[computer]
        
class Game:
    def game_judge(self):
        player = Player().gesture()
        AIPlayer().play_data.append(player)
        aiplayer = AIPlayer().ai_gesture()
        if (player == '剪刀' and aiplayer == '布') or \
        (player == '石头' and aiplayer == '剪刀') or\
        (player == '布' and aiplayer == '石头'):  
            print(f'电脑出的手势是{aiplayer},恭喜你赢了！')
        elif player == aiplayer:
            print(f'电脑出的手势是{aiplayer},打成平局了！')
        else :
            print(f'电脑出的手势是{aiplayer},你输了,再接再厉！')     

    def game_start(self):
        self.game_judge()
        while True:
            option = input('是否继续(y/n):')
            if option == 'y':
                self.game_judge()
            else :
                print('拜拜！')
                break

g = Game()
g.game_start()  


















